from django.db import models

# Create your models here.
from LoginSign.models import User
from products.models import goods_info
from django.utils import timezone

#订单表
class mall_order(models.Model):
    # order_id =models.AutoField(primary_key=True)#订单ID
    order_no = models.IntegerField()#订单编码
    user_id = models.ForeignKey(User,on_delete=models.CASCADE,related_name='orders')#用户ID
    total_price = models.DecimalField(max_digits=5, decimal_places=2)#总价
    pay_status = models.CharField(max_length=64)#支付状态
    pay_type = models.CharField(max_length=64)#支付类型
    pay_time = models.DateField(auto_now_add=True)#支付时间
    order_status =models.CharField(max_length=64)#订单状态
    extra_info =models.TextField(max_length=64)#备注
    is_deleted = models.BooleanField()#是否删除
    create_time = models.DateTimeField(default=timezone.now)#创建时间
    update_time = models.DateTimeField(default=timezone.now)#更新时间

# 订单项表
class order_item(models.Model):
    # order_item_id = models.AutoField(primary_key=True)  # 订单项ID
    order_id = models.ForeignKey(mall_order,models.CASCADE,related_name='items')  # 订单ID
    goods_id = models.ForeignKey(goods_info,models.CASCADE,related_name='items')  # 商品ID
    goods_name = models.CharField(max_length=32)  # 商品名称
    goods_cover_img = models.CharField(max_length=500)  # 商品封面图片
    selling_price = models.DecimalField(max_digits=5, decimal_places=2)  # 销售价格
    goods_count = models.IntegerField()  # 商品数量
    create_time = models.DateTimeField(default=timezone.now)  # 创建时间

# 订单地址表
class order_address(models.Model):
    order_id = models.ForeignKey(mall_order,models.CASCADE,related_name='adresses')  # 订单ID
    user_name = models.CharField(max_length=32)  # 收货人姓名
    user_phone = models.CharField(max_length=64)  # 收货人电话
    province_name = models.CharField(max_length=32)  # 省
    city_name = models.CharField(max_length=32)  # 市
    region_name = models.CharField(max_length=32)  # 地区
    detail_address = models.CharField(max_length=32)  # 详细地址
